package mr.ali.video.web.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import mr.ali.video.web.mapper.OpenIdMapper;
import mr.ali.video.web.model.OpenId;
import mr.ali.video.web.service.IOpenIdService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author Mr-ali
 * @since 2024-09-16
 */
@Service
public class OpenIdServiceImpl extends ServiceImpl<OpenIdMapper, OpenId> implements IOpenIdService {

   @Resource
   private OpenIdMapper openIdMapper;

   @Override
   public PageInfo<OpenId> getOpenId(Integer pageNum, Integer pageSize) {
      QueryWrapper<OpenId> queryWrapper = new QueryWrapper<>();
      queryWrapper.orderByDesc("id");
      PageHelper.startPage(pageNum, pageSize);
      List<OpenId> openIdList = openIdMapper.selectList(queryWrapper);
      return new PageInfo<>(openIdList);
   }

   @Override
   public OpenId getOpenIdByOpenId(Integer id) {
      OpenId openId = openIdMapper.selectById(id);
      return openId;
   }

   /**
    * 会员身份变成非会员
    */
   @Override
   public Integer deleteStatus(Integer id, Integer status) {
      Integer integer = openIdMapper.deleteStatus(id, status);
      return integer;
   }

   /**
    * 非会员身份变成会员
    */
   @Override
   public Integer updateOpenId(Integer id, Integer status, Long statusCreate) {
      Integer integer = openIdMapper.updateStatus(id, status, statusCreate);
      return integer;
   }

   /**
    * 会员总数量
    */
   @Override
   public Integer getUserCount(Integer status) {
      QueryWrapper<OpenId> queryWrapper = new QueryWrapper<>();
      queryWrapper.eq("status", status);
      Integer list = openIdMapper.selectCount(queryWrapper);
      return list;
   }
   /**
    * 会员总数量
    */
   @Override
   public Integer getUserCountBy() {
      QueryWrapper<OpenId> queryWrapper = new QueryWrapper<>();
      Integer list = openIdMapper.selectCount(queryWrapper);
      return list;
   }
}
